(*****************************************************************************
 * Delphi Plug-in Framework (DPF)
 * Copyright (C) 2006-2007 Tao Yuan
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the
 * License at http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.                                                               }
 *
 * The Initial Developer of the Original Code is Tao Yuan. Portions created by
 * Tao Yuan are Copyright (C) Tao Yuan (taoy.cn att gmail dott com)
 * All rights reserved.
 *****************************************************************************)
unit RDManifestInfoHandler;

interface

uses
  Classes,
  Rcl,
  RDConsts, RDModel, RDBaseHandler;

type
  TManifestInfoHandler = class(TBaseHandler)
  private
    manifest: TModelManifestInfo;
  public
    constructor Create(anEntityResolver: IEntityResolver);
    procedure characters(const ch : SAXString); override;
    procedure endElement(const uri, localName, qName: SAXString); override;
    function getResult: TModelManifestInfo;
    procedure startElement(const uri, localName, qName: SAXString; const atts:
        IAttributes); override;
  end;

implementation

constructor TManifestInfoHandler.Create(anEntityResolver: IEntityResolver);
begin
  inherited Create(anEntityResolver);
end;

procedure TManifestInfoHandler.characters(const ch : SAXString);
begin
  // ignore all characters
end;

procedure TManifestInfoHandler.endElement(const uri, localName, qName:
    SAXString);
begin
  log.debug('endElement - [' + uri + ']/[' + localName //$NON-NLS-1$ //$NON-NLS-2$
          + ']/[' + qName + ']'); //$NON-NLS-1$ //$NON-NLS-2$
  // no-op
end;

function TManifestInfoHandler.getResult: TModelManifestInfo;
begin
  Result := manifest;
end;

procedure TManifestInfoHandler.startElement(const uri, localName, qName:
    SAXString; const atts: IAttributes);
var
  name: string;
  docRef : TModelDocumentationReference;
begin
  log.debug('startElement - [' + uri + ']/[' //$NON-NLS-1$ //$NON-NLS-2$
          + localName + ']/[' + qName + ']'); //$NON-NLS-1$ //$NON-NLS-2$

  name := qName;
  if Rcl.Str.IsEqual('plugin', name) then //$NON-NLS-1$
  begin
      if (manifest <> nil) then
          raise ESAXException.Create('unexpected [' + name //$NON-NLS-1$
                  + '] element (manifest already defined)'); //$NON-NLS-1$

      manifest := TModelManifestInfo.Create;
      manifest.id := atts.getValue('id'); //$NON-NLS-1$
      manifest.Setversion(atts.getValue('version')); //$NON-NLS-1$
      manifest.vendor := atts.getValue('vendor'); //$NON-NLS-1$
  end
  else if Rcl.Str.IsEqual('plugin-fragment', name) then //$NON-NLS-1$
  begin
      if (manifest <> nil) then
          raise ESAXException.Create('unexpected [' + name //$NON-NLS-1$
                  + '] element (manifest already defined)'); //$NON-NLS-1$

      manifest := TModelManifestInfo.Create;
      manifest.Id := (atts.getValue('id')); //$NON-NLS-1$
      manifest.setVersion(atts.getValue('version')); //$NON-NLS-1$
      manifest.Vendor := (atts.getValue('vendor')); //$NON-NLS-1$
      manifest.PluginId := atts.getValue('plugin-id'); //$NON-NLS-1$
      if (atts.getValue('plugin-version') <> '') then //$NON-NLS-1$
          manifest.SetpluginVersion(
                  atts.getValue('plugin-version')); //$NON-NLS-1$

      if (atts.getValue('match') <> '') then //$NON-NLS-1$
          manifest.match := (atts.getValue('match')) //$NON-NLS-1$
      else
          manifest.match := (MATCH_COMPATIBLE);

  end
  else
  begin
    // ignore all other elements
  end;
end;

end.
